var dbConfig = require('../util/dbconfig')

//获取头条比赛
getHeadLineMatch = (req, res) => {
    // var sql = "select * from matchs where competition = '英超' order by startTime limit 4";
    // var sql = "select * from matchs where competition = '西甲' order by startTime limit 1";
    // var sql = "select * from matchs where competition = '意甲' order by startTime limit 1";
    // var sql = "select * from matchs where competition = '德甲' order by startTime limit 1";
    var sql = "select * from matchs order by startTime DESC limit 4";
    var sqlArr = [];
    var callBack = (err, conn) => {
        if (err) {
            // console.log('连接出错！')
            console.log(err);
        } else {
            res.send({
                status: 200,
                msg: 'GET请求成功',
                data: conn
            })
        }
    }
    dbConfig.sqlConnect(sql, sqlArr, callBack)
}

//获取英超比赛
getPremierLeagueMatch = (req, res) => {
    var sql = "select * from matchs where competition = '英超' order by startTime DESC ";
    var sqlArr = [];
    var callBack = (err, conn) => {
        if (err) {
            // console.log('连接出错！')
            console.log(err);
        } else {
            res.send({
                status: 200,
                msg: 'GET请求成功',
                data: conn
            })
        }
    }
    dbConfig.sqlConnect(sql, sqlArr, callBack)
}

//获取西甲比赛
getLaLigaMatch = (req, res) => {
    var sql = "select * from matchs where competition = '西甲' order by startTime DESC ";
    var sqlArr = [];
    var callBack = (err, conn) => {
        if (err) {
            // console.log('连接出错！')
            console.log(err);
        } else {
            res.send({
                status: 200,
                msg: 'GET请求成功',
                data: conn
            })
        }
    }
    dbConfig.sqlConnect(sql, sqlArr, callBack)
}

//获取法甲比赛
getFrenchArmourMatch = (req, res) => {
    var sql = "select * from matchs where competition = '法甲' order by startTime DESC ";
    var sqlArr = [];
    var callBack = (err, conn) => {
        if (err) {
            // console.log('连接出错！')
            console.log(err);
        } else {
            res.send({
                status: 200,
                msg: 'GET请求成功',
                data: conn
            })
        }
    }
    dbConfig.sqlConnect(sql, sqlArr, callBack)
}

//获取意甲比赛
getSerieAMatch = (req, res) => {
    var sql = "select * from matchs where competition = '意甲' order by startTime DESC ";
    var sqlArr = [];
    var callBack = (err, conn) => {
        if (err) {
            // console.log('连接出错！')
            console.log(err);
        } else {
            res.send({
                status: 200,
                msg: 'GET请求成功',
                data: conn
            })
        }
    }
    dbConfig.sqlConnect(sql, sqlArr, callBack)
}

//获取德甲比赛
getTheBundesligaMatch = (req, res) => {
    var sql = "select * from matchs where competition = '德甲' order by startTime DESC d";
    var sqlArr = [];
    var callBack = (err, conn) => {
        if (err) {
            // console.log('连接出错！')
            console.log(err);
        } else {
            res.send({
                status: 200,
                msg: 'GET请求成功',
                data: conn
            })
        }
    }
    dbConfig.sqlConnect(sql, sqlArr, callBack)
}





module.exports = {
    getHeadLineMatch,
    getPremierLeagueMatch,
    getLaLigaMatch,
    getFrenchArmourMatch,
    getSerieAMatch,
    getTheBundesligaMatch
}